<%@ page pageEncoding="UTF-8" %>
<%@ include file="common/global.jsp" %>
<%@ taglib prefix="security" uri="/security" %>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="common/meta.jsp" %>
    <title><f:message key="common.title"/> - <f:message key="login"/></title>
    <%@ include file="common/css.jsp" %>
</head>

<body class="login">
<security:user>
    <c:redirect context="${BASE}" url="/admin"/>
</security:user>
<div class="account-container login stacked">

    <div class="content clearfix">

        <form id="login_form">

            <h3><f:message key="login"/> </h3>

            <div class="login-fields">

                <div class="field">
                    <label for="username"><f:message key="user.username"/> :</label>
                    <input type="text" id="username"  name="username" placeholder="<f:message key="user.username"/>" class="login username-field ext-required" />
                </div> <!-- /field -->

                <div class="field">
                    <label for="password"><f:message key="user.password"/> :</label>
                    <input type="password" id="password" name="password"  placeholder="<f:message key="user.password"/>" class="login password-field ext-required"/>
                </div> <!-- /password -->

            </div> <!-- /login-fields -->

            <div class="login-actions">

				<span class="login-checkbox">
					<input id="rememberMe" name="rememberMe"  type="checkbox" class="field login-checkbox"  tabindex="4" />
					<label class="choice" for="rememberMe"><f:message key="login.remeber_username"/> </label>
				</span>

                <button class="button btn btn-primary btn-large"><f:message key="login"/> </button>

            </div> <!-- .actions -->

        </form>

    </div> <!-- /content -->

</div> <!-- /account-container -->


<%@ include file="common/js.jsp" %>
<script type="text/javascript">
    $(function() {
        var mainURL = BASE + '/admin';

        $('#login_form').ajaxForm({
            type: 'post',
            url: BASE + '/login',
            dataType: 'json',
            beforeSubmit: function() {
                return Smart.Validator.checkRequired('login_form');
            },
            success: function(result) {

                if (result.success) {
                    location.href = mainURL;
                } else {
                    alert(Smart.i18n('login.failure'));
                    $('#login_form').find(':input').prop('disabled', false);

                }
            }
        });
    });
</script>

</body>
</html>